package hotel.meituan.oversea.biz.task;

import hotel.base.oversea.constant.CommonConstants;
import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.utils.GsonUtils;
import hotel.base.oversea.utils.Result;
import hotel.meituan.oversea.api.vo.up.response.hotel.MtHotelDetailVo;
import hotel.meituan.oversea.biz.config.service.RedisService;
import hotel.meituan.oversea.biz.service.MtHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;


@Slf4j
@Component
public class MeituanUpdateBasicHotelsDetailTask {
    @Autowired
    private RedisService redisService;

    @Autowired
    private MtHotelService mtHotelService;

    //@Async 标识这个方法异步执行，可返回void或Future
    @Async
    public void executeBasicHotels(List<Long> hotelsList,String timestampIndex){//酒店id  产品+房型
        log.info(" {} >>>>>>>>> 异步线程 MeituanUpdateBasicHotelsDetailTask  开始执行时间：{}",timestampIndex,DateUtil.getNowTime());
        Result<Object> result = mtHotelService.getMtHotelDetail(hotelsList,null);
        if(null != result && result.getCode() == CommonConstants.SUCCESS){
            if(null != result.getData()){
                List<MtHotelDetailVo> voList = (List<MtHotelDetailVo>)result.getData();
                if(null == voList){
                    log.error("timestampIndex={}    voList  为空",timestampIndex);
                }else{
                    log.info("timestampIndex={}    voList.size={}",voList.size());
                }
                redisService.lPush("basic_hotel_save_queue_twenty", GsonUtils.GsonString(voList));//保存到酒店详情队列，另起一个定时器跑保存更新酒店详情
            }
        }else{
            log.error(DateUtil.getCurrTime()+" 获取酒店数据失败："+GsonUtils.GsonString(result));
        }
    }

}
